<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>词法作用域</title>
</head>

<body>

</body>
<script>
    //全局作用域****************************************
    function foo(a) {
        //foo创建的作用域***********************
        var b = a * 2;
        function bar(c) {
            //bar创建的作用域****************
            console.log(a, b, c);
            //bar创建的作用域****************
        }

        foo(2);
        //foo创建的作用域***********************
    }
    //全局作用域****************************************

    // 欺骗作用域
    function too(str, a) {
        eval(str);  //修改词法作用域
        console.log(a, b);
    }
    var b = 2;
    too("var b=3", 1);//输出1,3

    // 严格模式下的eval
    function soo(str, a) {
        "use strict";
        eval(str);
        console.log(a);
    }
    soo("var a = 2");//undefined
</script>

</html>